
var tweet = {
	width:500,
	height:250,
	uid : 0,
	motionhandler:0
};

function test(aa){
	alert(aa);
}


tweet.win = (function(){
	return {
		init : function(){
			document.onselectstart = function() {
				return false;
			};
			// 处理 窗体拖动事件
			win_head.onmousedown = function() {
				AlloyDesktop.drag();
			};
			win_head.onmouseup = function() {
				AlloyDesktop.stopDrag();
			};
			
			cancel.onclick = function(){
				AlloyDesktop.close();
			};

			submit.onclick = function(){
				var content = $('#content').val();
				api.pubTweet(tweet.uid, content , function(data){
					var result = Parse.result(data);
					if(result.code==1){
						AlloyDesktop.close();
					}else{
						$('.msg').html(result.message);
					}
				});
			};

			$('.emotion').click(function(){

			});
			$('.images').click(function(){

			});
			$('.app').click(function(){
				var content = $('#content').val();
				content += "#插入开源软件#";
				$('#content').val(content);
			});

			$('#emotion').click(function(){
				var offset = $(this).offset();
				var position = AlloyDesktop.getPos();
				console.info(offset);
				var rootPath = Util.local.get("rootPath");
				var epos = $('#content')[0].selectionStart;
				tweet.motionhandler = help.alloy.createToolWindow(rootPath+'src/views/Emotion.html', {"opener":handler, "x":(offset.left+position.x), "y":(offset.top+position.y), "epos":epos});
				//AlloyDesktop.execJS("aa();" , h);

			});
		},

		selectEmotion : function(motion,pos){
			var mo = "["+motion+"]";
			var content = $('#content').val();
			content = content.substring(0, pos)+mo+content.substring(pos, content.length);
			$('#content').val(content);
			$('#content').focus();
			$('#content')[0].selectionStart =pos + mo.length;
			$('#content')[0].selectionEnd =pos + mo.length;
		}
	};
})();

tweet.init = (function(){
	return {
		init : function(){
			tweet.win.init();
			tweet.uid =  help.alloy.getParam('uid');
			console.info(tweet.uid);
			//tweet.view.init();
		},
		readyHandler : function(){
			AlloyDesktop.setTitle("动弹一下");
			AlloyDesktop.hide();
			var win = AlloyDesktop.getScreenSize();
			var x = (win.width-tweet.width)/2;
			var y = (win.height-tweet.height)/2;
			AlloyDesktop.move(x,y);
			AlloyDesktop.setSize(tweet.width,tweet.height);
			AlloyDesktop.restore();
			AlloyDesktop.focus();
			//AlloyDesktop.enableResize();
			tweet.init.init();
		}
	};
})();

